package com.linwen.excise.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName _49字母异位词分组
 * @Description TODO
 * @Author zero
 * @DATE 2024/2/23 2:14 AM
 * @Version 1.0
 */
public class _49字母异位词分组 {
    public static void main(String[] args) {
        String[] arr = new String[]{"eat", "tea", "tan", "ate", "nat", "bat"};
        System.out.println(groupAnagrams(arr));
    }

    public static List<List<String>> groupAnagrams(String[] strs) {
        return new ArrayList<>(Arrays.stream(strs)
                .collect(Collectors.groupingBy(
                        s -> {
                            char[] charArray = s.toCharArray();
                            Arrays.sort(charArray);
                            return String.valueOf(charArray);
                        }))
                .values());
    }

}
